var form;
var $;
var jquery;
var layer;
var table;
$(function(){
    layui.use(['layer', 'table'], function () {
        layer=layui.layer;
        table=layui.table;
        $=layui.$;
        table_id=table.render({
            elem:'#table_id',
            url:'/Coupons/selectTable',
            cols:[[
                {checkbox:true},
                {field:'couponName',title:'优惠券名称',align:'center'},
                {field:'startDate',title:'开始时间',align:'center'},
                {field:'endDate',title:'结束时间',align:'center'},
                //{field: 'title', title: '上架/下架', align: 'center'},
                {field:'title',title:'上架/下架',align:'center',templet:function(d){
                        if(d.online==2){
                            return  "<input type='checkbox' checked name='opan' value=\""+d.couponId+"\" lay-skin='switch'  >"
                        }else if(d.online==3){
                            return  "<input type='checkbox' name='close' lay-skin='switch' value=\""+d.couponId+"\">"
                        }else{
                            return  "<input type='checkbox' checked name='opan' value=\""+d.couponId+"\" lay-skin='switch'  >"
                        }
                        //return "<input type='checkbox' name='zzz' lay-skin='switch' lay-text='上架|下架'>";
                    }},
                {field:'grant',title:'发放方式',align:'center'},
                {field:'issueQuantity',title:'发行数',align:'center'},
                {field:'used',title:'剩余数',align:'center'},
                {field:'title',title:'操作',align:'center',templet:function(d){
                        return "<span ><a  onclick='javascript:(\""+d.couponId+"\")' style='color:#1ABC9C;'>查看</a></span>"+
                            "<span style='margin-left: 20px'><a  onclick='javascript:(\""+d.couponId+"\")' style='color:#1ABC9C;'>删除</a></span>"
                        //return "<a class='operation'>查看</a>  <a class='operation'>删除</a>";
                    }},
            ]],
            page: {
                limit: 5,//指定每页显示的条数
                limits: [5, 10, 15],//每页条数的选择项
            }, //开启分页
            data: [],
        });
    });
    function delCoupon(couponId){
        $.ajax({
            url:"/Coupons/delectTable",
            dataType:"json",
            type:"post",
            data:{"couponId":couponId},
            success:function(data){
                if(data.code==0){
                    layer.msg('删除成功');
                    //selCoupon();
                }
                /*
                if(data){
                    console.log("删除成功");
                    location.reload();
                }else{
                    console.log("删除失败");
                }
                */
            }
        });
    }
});
function selCoupon2(couponId){
    $('#proId').val(couponId);
    layer.open({
        type:2,
        content:"aaa.html",
        area:['1020px','500px'],
        end:function () {

        }
    })
}
function retrieve() {
    $("input").val("");
    type: "post",
        $(this).find("option:selected").removeAttr("selected");
    layer.open({
        type : 2,
        id:1,
        title : "<div style='color:#666666;font-weight: 600;background: #F8F8F8;'>555</div>",
        area : [ '670px', '500px' ],
        maxmin: true,
        shade : 0,
        offset: 'auto',
        content :"jjj.html",
        success:function(){
        }
    });
    window.layer_1=layer;
}

function addCoupon() {
    location.href="CouponAdded.html?";
}
